package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.*;

@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties("handler")
public class Travel extends BaseDomain{

    public static final Integer STATE_REJECT = 0;//拒绝
    public static final Integer STATE_NORMAL = 1;//草稿
    public static final Integer STATE_WAITING = 2;//待等待
    public static final Integer STATE_RELEASE = 3;//发布

    private String title;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT-8")
    private Date travelTime;

    private String perExpends; //人均消费

    private Integer days; //旅游时间

    private Integer person;//和谁旅游

    private User author;

    private Date createTime;
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT-8")
    private Date releaseTime;//发布时间
    //如果使用大布尔 所对应的get方法 是getIsPublic 属性值isPublic
    //如果是小布尔 所对应的get方法 是isPublic 属性值是Public 小布尔没有get打头 只有isXxx
    private Boolean isPublic;//是否公开

    private Region place;//旅游地区

    private String coverUrl;//封面

    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT-8")
    private Date lastUpdateTime;//最后更新时间

    private Integer state = STATE_NORMAL;//状态
    //关联旅游内容
    private TravelContent travelContent;
    //游记冗余字段记录点赞数
    private List<String> likeNums = new ArrayList<String>();
    //游记的收藏数
    private List<String> collectNums = new ArrayList<String>();
    //游记的评论数
    private List<String> comments = new ArrayList<String>();


    //获取状态的名称
    public String getStateName(){
        if(state==STATE_REJECT){
            return "拒绝";
        }else if(state==STATE_NORMAL){
            return "草稿";
        }else if(state==STATE_WAITING){
            return "待审核";
        }else if(state==STATE_RELEASE){
            return "发布";
        }
        return "";
    }

    public String getJSONString(){
        Map<String,Object> map = new HashMap<String,Object>();

        map.put("id",id );
        map.put("title",title );
        map.put("coverUrl",coverUrl );

        return JSONUtils.toJSONString(map);

    }


}